﻿using System;
using System.Collections.Generic;

namespace RioTinto.Helpers
{
    public static class ExtensionMethods
    {
        public static bool ContainsAll(this string value, params string[] values)
        {
            bool retVal = true;
            foreach (string s in values)
            {
                if (!value.Contains(s))
                {
                    retVal = false;
                    break;
                }
            }
            return retVal;
        }

        public static string RemoveAll(this string value, params string[] values)
        {
            foreach (string s in values)
            {
                value = value.Replace(s, string.Empty);
            }
            return value;
        }

        public static IEnumerable<T> Traverse<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> function)
        {
            foreach (T item in source)
            {
                yield return item;

                IEnumerable<T> list = function(item);
                if (list != null)
                {
                    foreach (T item2 in Traverse<T>(list, function))
                    {
                        yield return item2;
                    }
                }
            }
        }
    }
}
